﻿
﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
﻿using OilRigSumoWrestlers.Controllables.Controllers;
﻿using OilRigSumoWrestlers.Entities.MenuItems;
using RaptorEngine;
using RaptorEngine.Components.Drawable;

﻿namespace OilRigSumoWrestlers.Scenes.Menu

{
    public class MainMenu:MenuScene
    {
        public MainMenu() :base(false)
        {
            CreateHUD();
            CreateController();
        }
        private void CreateHUD()
        {
            Vector2 worldCenter = new Vector2(
                GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.X + GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.Width / 2,
                GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.Y + GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.Height / 2);

            //Text displayed with a "shadow"
            string mainMenuText = "Main Menu";

            Entity mainMenu = new Entity(worldCenter + new Vector2(0, -60));
            mainMenu.AddComponent(new DrawableText(mainMenu, 
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuFont"), mainMenuText, Color.White, 1, true));

            Entity mainMenuShadow = new Entity(worldCenter + new Vector2(0, -60)+Vector2.One);
            mainMenuShadow.AddComponent(new DrawableText(mainMenuShadow,
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuFont"), mainMenuText, Color.Black, 1, true));

            //Add texts to the scene
            AddEntity(mainMenuShadow);
            AddEntity(mainMenu);
           

            //Start Game text
            string singleplayerText = "Single Player";

            DrawableText optSingleplayerGameSelected = new DrawableText(new Entity(worldCenter + new Vector2(0, 40)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), singleplayerText, Color.White, 1, true);

            DrawableText optSingleplayerGame = new DrawableText(new Entity(worldCenter + new Vector2(0, 40)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), singleplayerText, Color.Gray, 1, true);

            //Multiplayer text
            string multiplayerText = "Multiplayer";

            DrawableText optMultiplayerSelected = new DrawableText(new Entity(worldCenter + new Vector2(0, 80)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), multiplayerText, Color.White, 1, true);

            DrawableText optMultiplayer = new DrawableText(new Entity(worldCenter + new Vector2(0, 80)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), multiplayerText, Color.Gray, 1, true);

            //Exit Game text
            string exitGameText = "Exit Game";

            DrawableText optExitGameSelected = new DrawableText(new Entity(worldCenter + new Vector2(0, 120)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), exitGameText, Color.White, 1, true);

            DrawableText optExitGame = new DrawableText(new Entity(worldCenter + new Vector2(0, 120)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), exitGameText, Color.Gray, 1, true);

            _menuItems.Add(new SingleplayerItem(optSingleplayerGameSelected, optSingleplayerGame));
            _menuItems.Add(new MultiplayerItem(optMultiplayerSelected, optMultiplayer));
            _menuItems.Add(new ExitGameItem(optExitGameSelected, optExitGame));
            _menuItems[_selectedItem].Select();

            foreach (MenuItem item in _menuItems)
            {
                AddEntity(item);
            }

        }

        private void CreateController()
        {
            Entity menuController = new Entity();
            menuController.AddComponent(new MenuControllable(menuController, this, RaptorEngine.Managers.LogicalPlayerIndex.One));
            AddEntity(menuController);
        }

        public override void GoBack()
        {
            GameEngine.Instance.Scene.RemoveCurrentScene();
            GameEngine.Instance.Scene.StartCurrentScene();
            GameEngine.Instance.Scene.ShowCurrentScene();
            base.GoBack();
        }

        public override void Update()
        {
            
        }
    }
}
